<template>
  <div>
    <!-- 课程预览 TODO -->
    <div class="ccInfo">
      <img :src="coursePublish.cover">
      <div class="main">
        <h2>{{ coursePublish.title }}</h2>
        <p class="gray">共&nbsp;<span style="color: #06e061">{{ coursePublish.lessonNum }}</span>&nbsp;课时</p>
        <p>所属分类：<span style="color: darkgoldenrod">{{ coursePublish.subjectParentTitle }}</span>&nbsp; —— &nbsp;<span style="color: #BF7FFC"> {{ coursePublish.subjectTitle }}</span></p>
        <p>课程讲师：<el-tag>{{ coursePublish.teacherName }}</el-tag>
        </p>
        <h3 class="red">￥{{ coursePublish.price }}</h3>
      </div>
    </div>
    <div style="text-align:center;margin-top: 20px;">
      <el-button
        type="primary"
        @click="prev"
      >上一步</el-button>
      <el-button
        type="primary"
        :disabled="publishBtnDisabled"
        @click="publish"
      >发布课程</el-button>
    </div>
  </div>
</template>
<script>
import { CourseApi } from '@/api/course/url-course'
import { getAction, putAction } from '@/api/manage'
export default {
  data() {
    return {
      // 按钮是否禁用
      publishBtnDisabled: false,
      coursePublish: {}
    }
  },
  created() {
    if (this.$parent.courseId) {
      this.fetchCoursePublishById(this.$parent.courseId)
    }
  },
  methods: {
    // 上一步
    prev() {
      this.$parent.active = 1
    },
    // 发布课程跳转
    publish() {
      this.publishBtnDisabled = true
      putAction(CourseApi.updateCoursePublishById, { id: this.$parent.courseId }).then(res => {
        if (res.success) {
          this.$message.success(res.message)
          this.$parent.active = 3
        } else {
          this.$message.error(res.message)
        }
      })
    },
    // 获取课程发布信息
    fetchCoursePublishById(id) {
      getAction(CourseApi.getCoursePublishById, { id: id }).then(res => {
        if (res.success) {
          this.coursePublish = res.data.item
        } else {
          this.$message.error("获取课程信息失败")
        }
      })
    }
  }
}
</script>
<style scoped>
.ccInfo {
  background: #f5f5f5;
  width: 90%;
  padding: 20px;
  overflow: hidden;
  border: 1px dashed #ddd;
  margin-bottom: 40px;
  position: relative;
  margin: auto;
}
.ccInfo img {
  background: #d6d6d6;
  width: 500px;
  height: 278px;
  display: block;
  float: left;
  border: none;
  margin-left: 200px;
}
.ccInfo .main {
  margin-left: 750px;
}
.ccInfo .main h2 {
  font-size: 28px;
  margin-bottom: 30px;
  line-height: 1;
  font-weight: normal;
  color: #3cd3fa;
}
.ccInfo .main p {
  margin-bottom: 10px;
  word-wrap: break-word;
  line-height: 24px;
  max-height: 48px;
  overflow: hidden;
}
.ccInfo .main p {
  margin-bottom: 10px;
  word-wrap: break-word;
  line-height: 24px;
  max-height: 48px;
  overflow: hidden;
}
.ccInfo .main h3 {
  left: 760px;
  bottom: 20px;
  line-height: 1;
  font-size: 28px;
  color: #d32f24;
  font-weight: normal;
  position: absolute;
}
</style>